package com.zzf.concurrent.example.design.pattern.active.object;

/**
 * @author GaoFeng2017
 * @date 2019/9/11 14:42
 */
public class SchedulerThread extends Thread {

    private final ActivationQueue queue;

    public SchedulerThread(ActivationQueue queue) {
        this.queue = queue;
    }

    public void putRequest(MethodRequest request) {
        this.queue.put(request);
    }

    @Override
    public void run() {
        this.consumeRequest();
    }

    private void consumeRequest() {
        while (true) {
            MethodRequest request = this.queue.poll();
            request.execute();
        }
    }
}
